package simulation;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * 时间表类
 * 记录模板路径表
 */
public class Timetable {
    private static final ArrayList<Path> paths0 = new ArrayList<>();
    private static final ArrayList<Path> paths1 = new ArrayList<>();
    private static final ArrayList<Path> paths2 = new ArrayList<>();
    private static final ArrayList<Integer> timePoints0 = new ArrayList<>();
    private static final ArrayList<Integer> timePoints1 = new ArrayList<>();
    private static final ArrayList<Integer> timePoints2 = new ArrayList<>();

    public static ArrayList<Path> getPaths(int type) {
        return switch (type) {
            case 0 -> paths0;
            case 1 -> paths1;
            case 2 -> paths2;
            default -> throw new IllegalStateException("Unexpected value: " + type);
        };
    }

    public static ArrayList<Integer> getTimePoints(int type) {
        return switch (type) {
            case 0 -> timePoints0;
            case 1 -> timePoints1;
            case 2 -> timePoints2;
            default -> throw new IllegalStateException("Unexpected value: " + type);
        };
    }

    /**
     * 时间表之初始化函数
     * 初始化三种时间表
     */
    public static void initTimetables() throws FileNotFoundException {
        File timetable = new File("timetable.txt");
        Scanner myScanner = new Scanner(timetable);

        int type = 0;
        while (myScanner.hasNextLine()) {
            int timePoint, startSpace, endSpace;
            timePoint = myScanner.nextInt();
            startSpace = myScanner.nextInt();
            endSpace = myScanner.nextInt();

            if (timePoint != -1) {
                getTimePoints(type).add(timePoint);
                getPaths(type).add(new Path(startSpace, endSpace));
            }
            else
                type++;
        }
    }
}